package GUI;
import java.awt.Color;
import java.awt.Font;
import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.Timer;

/**
* This class displays a digital clock on the screen.

*/
public class DigitalClock extends JPanel implements ActionListener {

	
	JLabel timeLabel = new JLabel();
	//SimpleDateFormat sdf = new SimpleDateFormat("MMM dd,yyyy  HH:mm:ss");
	SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy   HH:mm:ss");
	Timer timer;
	
	public DigitalClock() {
		// Run the constuctor for the parent JFrame class.
		super();

		// Exit the program when the user closes the window.
		

		// Get the current system time and display it
		// according to the format we defined.
		timeLabel.setText(sdf.format(new Date(System.currentTimeMillis())));
         
		// Set a larger, nicer font for the digital clock than the default.
		timeLabel.setFont(new Font("Dialog", Font.PLAIN, 24));

		// Set the timer to update the clock every 500 milliseconds (0.5 seconds)
		timer = new Timer(500, this);
		timer.setRepeats(true);
		timer.start();

		// Add the time display to the window and make it visible.
		this.add(timeLabel);
		this.setVisible(true);

		}

	public JLabel getTimeLabel() {
		return timeLabel;
	}

	public void setTimeLabel(JLabel timeLabel) {
		this.timeLabel = timeLabel;
	}
	
	

	public void actionPerformed(ActionEvent e) {
		// If the timer caused this event.
		if (e.getSource().equals(timer)) {
		// Then set a new time.
		timeLabel.setText(sdf.format(new Date(System.currentTimeMillis())));
		}

		}

	

		

	
}


